package com.mc.servlet;

import com.mc.bean.Jury;
import com.mc.bean.Teacher;
import com.mc.service.JuryService;
import com.mc.service.impl.JuryServiceImpl;
import org.junit.Test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zh
 */
@WebServlet("/jurypass.action")
public class JuryPassServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建评委逻辑对象
        JuryService juryService=new JuryServiceImpl();
        //获取值
        String oldpass=req.getParameter("oldpass");
        String newpass=req.getParameter("newpass");
        //输出
        System.out.println(oldpass);
        System.out.println(newpass);
        //得到当前登录人的密码
        Jury jury=(Jury) req.getSession().getAttribute("user");
        //判断
        if(oldpass.equals(jury.getJurypassword())){
            //设置新密码
            jury.setJurypassword(newpass);
            boolean flag=juryService.update(jury);
            System.out.println(flag);
            //重定向
            resp.sendRedirect("userlogin.jsp");
        }else{
            System.out.println("原密码错误");
            req.setAttribute("mess","原密码错误");
            //转发到jurypass.jsp
            req.getRequestDispatcher("jurypass.jsp").forward(req,resp);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
